package com.shopx.auth.controller;

import com.shopx.auth.bean.SysOrg;
import com.shopx.auth.model.SysOrgModel;
import com.shopx.auth.service.ISysOrgService;
import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.base.anno.ShopxParamAnno;
import com.shopx.base.controller.BaseController;
import com.shopx.base.dto.Result;
import com.shopx.base.exception.ShopxException;
import com.shopx.base.utils.ResultUtil;
import com.shopx.cmm.DTO.PageDTO;
import com.shopx.core.common.CommonConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lituo
 * @className: SysConfigController
 * @description: 组织机构
 * @date 2021/12/5 12:04 PM
 */
@RestController
@Slf4j
@RequestMapping(value = "/sysOrg")
public class SysOrgController extends BaseController {

  @Autowired
  private ISysOrgService sysOrgService;

  @PostMapping(value = "/queryPageList")
  @ShopxParamAnno
 public Result<PageDTO> queryPageList(@RequestBody SysOrgModel sysOrg) throws ShopxException {
    PageDTO<SysOrgModel> pageDTO = sysOrgService.getListPage(sysOrg);
    return ResultUtil.ok(pageDTO);
  }

  @PostMapping(value = "/insertOne")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
public Result<Integer> insertOne(@RequestBody SysOrg sysOrg) throws ShopxException {
    int result = sysOrgService.insertSelective(sysOrg);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/updateOne")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
public Result<Integer> updateOne(@RequestBody SysOrg sysOrg) throws ShopxException {
    int result = sysOrgService.updateByPrimaryKeySelective(sysOrg);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/queryOneByPrimaryKey")
  public Result<SysOrgModel> queryOneByPrimaryKey(@RequestBody SysOrg sysOrg) throws ShopxException {
    SysOrgModel result = sysOrgService.selectByPrimaryKey(sysOrg);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/queryOrgNodeList")
  public Result<List> queryOrgNodeList() {
    List<SysOrgModel> list = sysOrgService.queryOrgNodeList();
    return ResultUtil.ok(list);
  }

  @PostMapping(value = "/deleteChecked")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
public Result<Integer> deleteChecked(@RequestBody SysOrg sysOrg) throws ShopxException {
    int result = sysOrgService.deleteByPrimaryKey(sysOrg);
    return ResultUtil.ok(result);
  }

  @PostMapping(value = "/selectOrgTreeList")
  public Result<List> selectOrgTreeList(@RequestBody SysOrgModel sysOrg) throws ShopxException {
    List<SysOrgModel> list = sysOrgService.selectOrgTreeList(sysOrg);
    return ResultUtil.ok(list);
  }

    @RequestMapping(value = "/queryOrgTreeList")
    @ShopxParamAnno
    public Result<?> queryOrgTreeList(String parUrlId) {
        String s = sysOrgService.queryOrgTreeList(parUrlId);
        return ResultUtil.ok(s);
    }

    @RequestMapping(value = "/queryEditOrgNodeList")
    @ShopxParamAnno
    public Result<?> queryEditOrgNodeList(@RequestBody SysOrgModel sysOrg) {
        String s = sysOrgService.queryEditOrgNodeList(sysOrg);
        return ResultUtil.ok(s);
    }
}

